package org.dinqy.impl;

import org.dinqy.ClauseBeanFactory;
import org.dinqy.Criterion;
import org.dinqy.syntax.AndOr;
import org.dinqy.syntax.Finder;

/**
 * @author armandino (at) gmail.com
 */
public final class WhereNode<T> extends ResultListNode<T> implements Finder<T> {
    
    public WhereNode() {
        super(null); // no parent
    }
    
	public AndOr<T> where(String fieldName, Criterion criterion) {
	    setClauseBean(ClauseBeanFactory.where(fieldName, criterion));
	    return createSuccessor();
	}
	
	@Override
	public long count() {
	    return getQueryExecutor().count(getEntityClass(), getClauseBeans());
	}
	
	private AndOr<T> createSuccessor() {
	    AndOrNode<T> successor = new AndOrNode<T>(this);
	    setSuccessor(successor);
	    return successor;
	}
}
